import {
	mySsoRequest
} from './api.js'
async function getMenu(options) {
	let companyId = uni.getStorageSync("companyId");
	let appId = uni.getStorageSync("appId");
	if (!companyId && !appId) {
		uni.showToast({
			title: "获取目录失败，请重新登录",
			icon: "none",
			duration: 2000
		})
		setTimeout(() => {
			uni.redirectTo({
				url: '/pages/login/login'
			})
		}, 2100)
	}
	const res = await mySsoRequest({
		url: "/icore.icp.web/pass/v1/sysmenus/findMenusByUserId",
		method: "GET",
		maskTitle: "",
		showLoading: true,
		maskTitle: "正在获取菜单",
		data: {
			companyId: companyId,
			appId: appId
		},
	})
	console.log("getMuen", res.data);
	if (res.data.code == 0) {
		let arr = res.data.data.map((item) => {
			if (item.menuLabel == options.type) {
				return item.children
			}
		}).flat().map((item) => {
			if (item && item.menuIcon != null && item.menuIcon != "") {
				item.extraIcon = {
					color: '#00aded',
					size: '22',
					type: item.menuIcon
				}
				if (item.menuIcon.includes('wl')) {
					item.extraIcon.customPrefix = 'iconfont'
				}
			}
			return item
		}).filter((item) => {
			return item
		})
		return arr

	} else {
		uni.showToast({
			title: "获取目录失败，请重新登录",
			icon: "none",
			duration: 2000
		})
		setTimeout(() => {
			uni.redirectTo({
				url: '/pages/login/login'
			})
		}, 2100)
	}

}

module.exports = {
	getMenu: getMenu //导出
}